package com.yifang.yibingproject.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SystemContext {

    /**
     * 获取当前用户id，如果未登录，则返回游客id=guest
     * @return
     */
    public static Long getCurrentUserId(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null) {
            return Long.valueOf(authentication.getPrincipal()+"");
        }
        return 1l;
    }
}
